home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 1.iso / dist / fw_teTeX.idb / usr / freeware / bin / texexec.z / texexec
Text File  |  2001-01-10  |  56KB  |  1,413 lines

  1. eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q'
  2.         if 0;
  3.  
  4. #D We started with a hack provided by Thomas Esser. This
  5. #D expression replaces the unix specific line \type
  6. #D {#!/usr/bin/perl}.
  7.  
  8. # in a few versions DetermineNOfPdfPages is obsolete
  9.  
  10. # nog doen: automatisch log scannen op overfull en missing
  11. # fastmode tzt anders: \iffastmode \fi
  12.  
  13. #D \module
  14. #D   [       file=texexec.pl,
  15. #D        version=1999.11.03,
  16. #D          title=running \ConTeXt,
  17. #D       subtitle=\TEXEXEC,
  18. #D         author=Hans Hagen,
  19. #D           date=\currentdate,
  20. #D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
  21. #C
  22. #C This module is part of the \CONTEXT\ macro||package and is
  23. #C therefore copyrighted by \PRAGMA. See licen-en.pdf for
  24. #C details.
  25.  
  26. #  Thanks to Tobias Burnus    for the german translations.
  27. #  Thanks to Thomas Esser     for hooking it into web2c
  28. #  Thanks to Taco   Hoekwater for suggesting improvements
  29.  
  30. use Cwd ;
  31. use Time::Local ;
  32. use Config ;
  33. use Getopt::Long ;
  34.  
  35. use strict ;
  36.  
  37. #D In this script we will launch some programs and other
  38. #D scripts. \TEXEXEC\ uses an ini||file to sort out where
  39. #D those programs are stored. Two boolean variables keep
  40. #D track of the way to call the programs. In \TEXEXEC,
  41. #D \type {$dosish} keeps track of the operating system.
  42. #D It will be no surprise that Thomas Esser provided me
  43. #D the neccessary code to accomplish this.
  44.  
  45. $ENV{"MPXCOMMAND"} = "0" ; # otherwise loop 
  46.  
  47. my $dosish  = ($Config{'osname'} =~ /dos|win/i) ;
  48.  
  49. my $TeXUtil   = 'texutil'  ;
  50. my $SGMLtoTeX = 'sgml2tex' ;
  51. my $FDFtoTeX  = 'fdf2tex'  ;
  52.  
  53. $Getopt::Long::passthrough = 1 ; # no error message
  54. $Getopt::Long::autoabbrev  = 1 ; # partial switch accepted
  55.  
  56. my $AddEmpty         = '' ;
  57. my $Alone            = 0 ; 
  58. my $Arrange          = 0 ;
  59. my $BackSpace        = '0pt' ;
  60. my $CenterPage       = 0 ;
  61. my $ConTeXtInterface = 'unknown'  ;
  62. my $Convert          = '' ;
  63. my $DoMPTeX          = 0 ;
  64. my $EnterBatchMode   = 0 ;
  65. my $Environment      = '' ;
  66. my $FastMode         = 0 ;
  67. my $FinalMode        = 0 ;
  68. my $Format           = '' ;
  69. my $HelpAsked        = 0 ;
  70. my $MainBodyFont     = 'standard' ;
  71. my $MainLanguage     = 'standard' ;
  72. my $MakeFormats      = 0 ;
  73. my $Markings         = 0     ;
  74. my $Mode             = '' ;
  75. my $NoArrange        = 0 ;
  76. my $NoDuplex         = 0 ;
  77. my $NOfRuns          = 7 ;
  78. my $NoMPMode         = 0 ;
  79. my $OutputFormat     = 'standard' ;
  80. my $Pages            = '' ;
  81. my $PageScale        = '1000' ; # == 1.0 
  82. my $PaperFormat      = 'standard' ;
  83. my $PaperOffset      = '0pt' ;
  84. my $PassOn           = '' ;
  85. my $PdfArrange       = 0 ;
  86. my $PdfSelect        = 0 ;
  87. my $PdfCombine       = 0 ;
  88. my $PrintFormat      = 'standard' ;
  89. my $ProducePdf       = 0 ;
  90. my $Result           = 0 ;
  91. my $RunOnce          = 0 ;
  92. my $Selection        = '' ;
  93. my $Combination      = '2*4' ;
  94. my $SilentMode       = 0 ;
  95. my $TeXProgram       = '' ;
  96. my $TeXTranslation   = '' ;
  97. my $TextWidth        = '0pt' ;
  98. my $TopSpace         = '0pt' ;
  99. my $TypesetFigures   = 0 ;
  100. my $TypesetListing   = 0 ;
  101. my $TypesetModule    = 0 ;
  102. my $UseColor         = 0 ;
  103. my $Verbose          = 0 ;
  104. my $PdfCopy          = 0 ; 
  105.  
  106. &GetOptions
  107.   ( "arrange"       => \$Arrange          ,
  108.     "batch"         => \$EnterBatchMode   ,
  109.     "color"         => \$UseColor         ,
  110.     "centerpage"    => \$CenterPage       ,
  111.     "convert=s"     => \$Convert          ,
  112.     "environment=s" => \$Environment      ,
  113.     "fast"          => \$FastMode         ,
  114.     "final"         => \$FinalMode        ,
  115.     "format=s"      => \$Format           ,
  116.     "help"          => \$HelpAsked        ,
  117.     "interface=s"   => \$ConTeXtInterface ,
  118.     "language=s"    => \$MainLanguage     ,
  119.     "bodyfont=s"    => \$MainBodyFont     ,
  120.     "make"          => \$MakeFormats      ,
  121.     "mode=s"        => \$Mode             ,
  122.     "module"        => \$TypesetModule    ,
  123.     "figures=s"     => \$TypesetFigures   ,
  124.     "listing"       => \$TypesetListing   ,
  125.     "mptex"         => \$DoMPTeX          ,
  126.     "noarrange"     => \$NoArrange        ,
  127.     "nomp"          => \$NoMPMode         ,
  128.     "once"          => \$RunOnce          ,
  129.     "output=s"      => \$OutputFormat     ,
  130.     "pages=s"       => \$Pages            ,
  131.     "paper=s"       => \$PaperFormat      ,
  132.     "passon=s"      => \$PassOn           ,
  133.     "pdf"           => \$ProducePdf       ,
  134.     "pdfarrange"    => \$PdfArrange       ,
  135.     "pdfselect"     => \$PdfSelect        ,
  136.     "pdfcombine"    => \$PdfCombine       ,
  137.     "pdfcopy"       => \$PdfCopy          ,
  138.     "scale=s"       => \$PageScale        ,
  139.     "selection=s"   => \$Selection        ,
  140.     "combination=s" => \$Combination      ,
  141.     "noduplex"      => \$NoDuplex         ,
  142.     "paperoffset=s" => \$PaperOffset      ,
  143.     "backspace=s"   => \$BackSpace        ,
  144.     "topspace=s"    => \$TopSpace         ,
  145.     "markings"      => \$Markings         ,
  146.     "textwidth=s"   => \$TextWidth        ,
  147.     "addempty=s"    => \$AddEmpty         ,
  148.  
  149.     "print=s"       => \$PrintFormat      ,
  150.     "results=s"     => \$Result           ,
  151.     "runs=s"        => \$NOfRuns          ,
  152.     "silent"        => \$SilentMode       ,
  153.     "tex=s"         => \$TeXProgram       ,
  154.     "verbose"       => \$Verbose          ,
  155.     "alone"         => \$Alone            ) ;
  156.  
  157. $SIG{INT} = "IGNORE" ;
  158.  
  159. if ($PdfArrange||$PdfSelect||$PdfCopy||$PdfCombine)     
  160.   { $ProducePdf = 1 ; 
  161.     $RunOnce = 1 }
  162.  
  163. if ($ProducePdf)     
  164.   { $OutputFormat = "pdf" }
  165.  
  166. if ($RunOnce||$Pages||$TypesetFigures||$TypesetListing) 
  167.   { $NOfRuns = 1 }
  168.  
  169. my $Program = " TeXExec 1.9 - ConTeXt / PRAGMA ADE 1997-2000" ;
  170.  
  171. print "\n$Program\n\n";
  172.  
  173. my $pathslash = '/' ; if ($0 =~ /\\/) { $pathslash = "\\" }
  174. my $cur_path  = ".$pathslash" ;
  175. my $own_path  = $0 ; $own_path =~ s/texexec\.(pl|bat|)//io ;
  176.  
  177. sub checked_path
  178.   { my $path = shift  ;
  179.     if ((defined($path))&&($path ne ''))
  180.       { $path =~ s/[\/\\]/$pathslash/go ;
  181.         $path =~ s/[\/\\]*$//go ;
  182.         $path .= $pathslash }
  183.     else
  184.       { $path = '' }
  185.     return $path }
  186.  
  187. sub checked_file
  188.   { my $path = shift  ;
  189.     if ((defined($path))&&($path ne ''))
  190.       { $path =~ s/[\/\\]/$pathslash/go }
  191.     else
  192.       { $path = '' }
  193.     return $path }
  194.  
  195. sub CheckPath
  196.   { my ($Key, $Value) = @_ ;
  197.     if ($Value =~ /\//)
  198.       { $Value = checked_path($Value) ;
  199.         unless (-d $Value)
  200.           { print "                 error : $Key set to unknown path $Value\n" } } }
  201.  
  202. # set <variable> to <value>
  203. # for <script> set <variable> to <value>
  204. # except for <script> set <variable> to <value>
  205.  
  206. my $IniPath = '' ;
  207.  
  208. #D The kpsewhich program is not available in all tex distributions, so
  209. #D we have to locate it before running it (as suggested by Thomas).
  210.  
  211. my @paths ;
  212.  
  213. if ($ENV{PATH} =~ /\;/)
  214.   { @paths = split(/\;/,$ENV{PATH}) }
  215. else
  216.   { @paths = split(/\:/,$ENV{PATH}) }
  217.  
  218. my $kpsewhich = '' ;
  219.  
  220. if ($IniPath eq '')
  221.   { foreach (@paths)
  222.       { my $p = checked_path($_) . 'kpsewhich' ;
  223.         if ((-e $p)||(-e $p . '.exe'))
  224.           { $kpsewhich = $p ;
  225.             $IniPath = `$kpsewhich --format="other text files" -progname=context texexec.ini` ;
  226.             chomp($IniPath) ;
  227.             last } }
  228.     if ($Verbose)
  229.       { if ($IniPath eq '')
  230.           { print "     locating ini file : kpsewhich not found in path\n" }
  231.         else
  232.           { print "     locating ini file : found by kpsewhich\n" } } }
  233.  
  234. #D Now, when we didn't find the \type {kpsewhich}, we have
  235. #D to revert to some other method. We could have said:
  236. #D
  237. #D\starttypen
  238. #D unless ($IniPath)
  239. #D   { $IniPath = `perl texpath.pl texexec.ini` }
  240. #D \stoptypen
  241. #D
  242. #D But loading perl (for the second time) take some time. Instead of
  243. #D providing a module, which can introduce problems with loading, I
  244. #D decided to copy the code of \type {texpath} into this file.
  245.  
  246. use File::Find ;
  247.  
  248. my ($ReportPath, $ReportName, $ReportFile)    = (0,0,1) ;
  249. my ($FileToLocate, $PathToStartOn)            = ('','') ;
  250. my ($LocatedPath, $LocatedName, $LocatedFile) = ('','','') ;
  251.  
  252. sub DoLocateFile # we have to keep on pruning
  253.   { if (lc $_ eq $FileToLocate)
  254.       { $LocatedPath = $File::Find::dir ;
  255.         $LocatedName = $_ ;
  256.         $LocatedFile = $File::Find::name }
  257.     if ($LocatedName) { $File::Find::prune = 1  } }
  258.  
  259. sub LocatedFile
  260.   { $PathToStartOn = shift ;
  261.     $FileToLocate = lc shift ;
  262.     if ($FileToLocate eq '')
  263.       { $FileToLocate = $PathToStartOn ;
  264.         $PathToStartOn = $own_path }
  265.     ($LocatedPath, $LocatedName, $LocatedFile) = ('','','') ;
  266.     if ($FileToLocate ne '')
  267.       { if (-e $cur_path . $FileToLocate)
  268.           { $LocatedPath = $cur_path ;
  269.             $LocatedName = $FileToLocate ;
  270.             $LocatedFile = $cur_path . $FileToLocate }
  271.         else
  272.           { $_ = checked_path($PathToStartOn) ;
  273.             if (-e $_ . $FileToLocate)
  274.               { $LocatedPath = $_ ;
  275.                 $LocatedName = $FileToLocate ;
  276.                 $LocatedFile = $_ . $FileToLocate }
  277.             else
  278.               { $_ = checked_path($PathToStartOn) ;
  279.                 if (/(.*?[\/\\]texmf[\/\\]).*/i)
  280.                   { my $SavedRoot = $1 ;
  281.                     File::Find::find(\&DoLocateFile, checked_path($1 . 'context/')) ;
  282.                     unless ($LocatedFile)
  283.                       { File::Find::find(\&DoLocateFile, $SavedRoot) } }
  284.                 else
  285.                   { $_ = checked_path($_) ;
  286.                     File::Find::find(\&DoLocateFile, $_) } } } }
  287.     return ($LocatedPath, $LocatedName, $LocatedFile) }
  288.  
  289. #D So now we can say:
  290.  
  291. unless ($IniPath)
  292.   { ($LocatedPath, $LocatedName, $IniPath) = LocatedFile($own_path,'texexec.ini') ;
  293.     if ($Verbose)
  294.       { if ($IniPath eq '')
  295.           { print "     locating ini file : not found by searching\n" }
  296.         else
  297.           { print "     locating ini file : found by searching\n" } } }
  298.  
  299. #D The last resorts:
  300.  
  301. unless ($IniPath)
  302.   { if ($ENV{TEXEXEC_INI_FILE})
  303.       { $IniPath = checked_path($ENV{TEXEXEC_INI_FILE}) . 'texexec.ini' ;
  304.         unless (-e $IniPath) { $IniPath = '' } }
  305.     if ($Verbose)
  306.       { if ($IniPath eq '')
  307.           { print "     locating ini file : no environment variable set\n" }
  308.         else
  309.           { print "     locating ini file : found by environment variable\n" } } }
  310.  
  311. unless ($IniPath)
  312.   { $IniPath = $own_path . 'texexec.ini' ;
  313.     unless (-e $IniPath) { $IniPath = '' }
  314.     if ($Verbose)
  315.       { if ($IniPath eq '')
  316.           { print "     locating ini file : not found in own path\n" }
  317.         else
  318.           { print "     locating ini file : found in own path\n" } } }
  319.  
  320. #D Now we're ready for loading the initialization file! We
  321. #D also define some non strict variables. Using \type {$Done}
  322. #D permits assignments.
  323.  
  324. my %Done ;
  325.  
  326. unless ($IniPath)
  327.   { $IniPath = 'texexec.ini' }
  328.  
  329. if (open(INI, $IniPath))
  330.   { if ($Verbose)
  331.       { print "               reading : $IniPath\n" }
  332.     while (<INI>)
  333.       { if (!/^[a-zA-Z\s]/oi)
  334.           { }
  335.         elsif (/except for\s+(\S+)\s+set\s+(\S+)\s*to\s*(.*)\s*/goi)
  336.           { my $one = $1 ; my $two= $2 ; my $three = $3 ;
  337.             if ($one ne $Done{"TeXShell"})
  338.               { $three =~ s/^[\'\"]// ; $three =~ s/[\'\"]$// ; $three =~ s/\s*$// ;
  339.                 if ($Verbose)
  340.                   { print "               setting : '$two' to '$three' except for '$one'\n" }
  341.                 $Done{"$two"} = $three ;
  342.                 CheckPath ($two, $three) } }
  343.         elsif (/for\s+(\S+)\s+set\s+(\S+)\s*to\s*(.*)\s*/goi)
  344.           { my $one = $1 ; my $two= $2 ; my $three = $3 ; $three =~ s/\s*$// ;
  345.             if ($one eq $Done{"TeXShell"})
  346.               { $three =~ s/^[\'\"]// ; $three =~ s/[\'\"]$// ;
  347.                 if ($Verbose)
  348.                   { print "               setting : '$two' to '$three' for '$one'\n" }
  349.                 $Done{"$two"} = $three ;
  350.                 CheckPath ($two, $three) } }
  351.         elsif (/set\s+(\S+)\s*to\s*(.*)\s*/goi)
  352.           { my $one = $1 ; my $two= $2 ;
  353.             unless (defined($Done{"$one"}))
  354.               { $two =~ s/^[\'\"]// ; $two =~ s/[\'\"]$// ; $two =~ s/\s*$// ;
  355.                 if ($Verbose)
  356.                   { print "               setting : '$one' to '$two' for 'all'\n" }
  357.                 $Done{"$one"} = $two ;
  358.                 CheckPath ($one, $two) } } }
  359.     close (INI) ;
  360.     if ($Verbose)
  361.       { print "\n" } }
  362. elsif ($Verbose)
  363.   { print "               warning : $IniPath not found, did you read 'texexec.rme'?\n" ;
  364.     exit 1 }
  365. else
  366.   { print "               warning : $IniPath not found, try 'texexec --verbose'\n" ;
  367.     exit 1 }
  368.  
  369. sub IniValue
  370.   { my ($Key,$Default) = @_ ;
  371.     if (defined($Done{$Key})) { $Default = $Done{$Key} }
  372.     if ($Verbose)
  373.       { print "          used setting : $Key = $Default\n" }
  374.     return $Default }
  375.  
  376. my $TeXShell          = IniValue('TeXShell'          , ''        ) ;
  377. my $SetupPath         = IniValue('SetupPath'         , ''        ) ;
  378. my $UserInterface     = IniValue('UserInterface'     , 'en'      ) ;
  379. my $UsedInterfaces    = IniValue('UsedInterfaces'    , 'en'      ) ;
  380. my $MpExecutable      = IniValue('MpExecutable'      , 'mpost'   ) ;
  381. my $MpToTeXExecutable = IniValue('MpToTeXExecutable' , 'mpto'    ) ;
  382. my $DviToMpExecutable = IniValue('DviToMpExecutable' , 'dvitomp' ) ;
  383. my $TeXProgramPath    = IniValue('TeXProgramPath'    , ''        ) ;
  384. my $TeXFormatPath     = IniValue('TeXFormatPath'     , ''        ) ;
  385. my $ConTeXtPath       = IniValue('ConTeXtPath'       , ''        ) ;
  386. my $TeXScriptsPath    = IniValue('TeXScriptsPath'    , ''        ) ;
  387. my $TeXExecutable     = IniValue('TeXExecutable'     , 'tex'     ) ;
  388. my $TeXVirginFlag     = IniValue('TeXVirginFlag'     , '-ini'    ) ;
  389. my $TeXPassString     = IniValue('TeXPassString'     , ''        ) ;
  390. my $TeXFormatFlag     = IniValue('TeXFormatFlag'     , ''        ) ;
  391.  
  392. my $FmtLanguage       = IniValue('FmtLanguage'       , ''        ) ; 
  393. my $FmtBodyFont       = IniValue('FmtBodyFont'       , ''        ) ; 
  394. my $TcXPath           = IniValue('TcXPath'           , ''        ) ; 
  395.  
  396. if (($FmtLanguage)&&($MainLanguage eq 'standard')) 
  397.   { $MainLanguage = $FmtLanguage } 
  398. if (($FmtBodyFont)&&($MainBodyFont eq 'standard')) 
  399.   { $MainBodyFont = $FmtBodyFont } 
  400.  
  401. if ($Verbose) { print "\n" }
  402.  
  403. unless ($TeXFormatFlag)
  404.   { if ($dosish) { $TeXFormatFlag = "&" } else { $TeXFormatFlag = "\\&" } }
  405.  
  406. if ($TeXProgram)
  407.   { $TeXExecutable = $TeXProgram }
  408.  
  409. my $fmtutil = '' ;
  410.  
  411. if ($Alone)
  412.   { if ($Verbose)
  413.       { print "     generating format : not using fmtutil\n" } }
  414. elsif ($TeXShell =~ /tetex|fptex/i)
  415.   { foreach (@paths)
  416.       { my $p = checked_path($_) . 'fmtutil' ;
  417.         if (-e $p)
  418.           { $fmtutil = $p ; last }
  419.         elsif (-e $p . '.exe')
  420.           { $fmtutil = $p . '.exe' ; last } }
  421.     if ($Verbose)
  422.       { if ($fmtutil eq '')
  423.           { print "      locating fmtutil : not found in path\n" }
  424.         else
  425.           { print "      locating fmtutil : found\n" } } }
  426.  
  427. unless ($TeXScriptsPath)
  428.   { $TeXScriptsPath = $own_path }
  429.  
  430. unless ($ConTeXtPath)
  431.   { $ConTeXtPath = $TeXScriptsPath }
  432.  
  433. if ($ENV{"HOME"})
  434.   { if ($SetupPath) { $SetupPath .= "," }
  435.     $SetupPath .= $ENV{"HOME"} }
  436.  
  437. if ($TeXFormatPath)  { $TeXFormatPath  =~ s/[\/\\]$// ; $TeXFormatPath  .= '/' }
  438. if ($ConTeXtPath)    { $ConTeXtPath    =~ s/[\/\\]$// ; $ConTeXtPath    .= '/' }
  439. if ($SetupPath)      { $SetupPath      =~ s/[\/\\]$// ; $SetupPath      .= '/' }
  440. if ($TeXScriptsPath) { $TeXScriptsPath =~ s/[\/\\]$// ; $TeXScriptsPath .= '/' }
  441.  
  442. my %OutputFormats ;
  443.  
  444. $OutputFormats{pdf}      = "pdftex" ;
  445. $OutputFormats{pdftex}   = "pdftex" ;
  446. $OutputFormats{dvips}    = "dvips" ;
  447. $OutputFormats{dvipsone} = "dvipsone" ;
  448. $OutputFormats{acrobat}  = "acrobat" ;
  449. $OutputFormats{dviwindo} = "dviwindo" ;
  450. $OutputFormats{dviview}  = "dviview" ;
  451.  
  452. my @ConTeXtFormats = ("nl", "en", "de", "cz", "uk") ;
  453.  
  454. my %ConTeXtInterfaces ;
  455.  
  456. $ConTeXtInterfaces{nl} = "nl" ; $ConTeXtInterfaces{dutch}        = "nl" ;
  457. $ConTeXtInterfaces{en} = "en" ; $ConTeXtInterfaces{english}      = "en" ;
  458. $ConTeXtInterfaces{de} = "de" ; $ConTeXtInterfaces{german}       = "de" ;
  459. $ConTeXtInterfaces{cz} = "cz" ; $ConTeXtInterfaces{czech}        = "cz" ;
  460. $ConTeXtInterfaces{uk} = "uk" ; $ConTeXtInterfaces{brittish}     = "uk" ;
  461. $ConTeXtInterfaces{xx} = "xx" ; $ConTeXtInterfaces{experimental} = "xx" ;
  462.  
  463. my %Help ;
  464.  
  465. $Help{ARRANGE}     = "             --arrange   process and arrange\n" ;
  466. $Help{BATCH}       = "               --batch   run in batch mode (don't pause)\n" ;
  467. $Help{CENTERPAGE}  = "          --centerpage   center the page on the paper\n" ;
  468. $Help{COLOR}       = "               --color   enable color (when not yet enabled)\n" ;
  469. $Help{CONVERT}     = "             --convert   converts file first\n" ;
  470. $Help{convert}     =
  471. $Help{CONVERT}     . "                           =xml  : XML => TeX\n"
  472.                    . "                           =sgml : SGML => TeX\n" ;
  473. $Help{ENVIRONMENT} = "         --environment   load some environments first\n" ;
  474. $Help{environment} =
  475. $Help{ENVIRONMENT} . "                           =name : list of environments\n" ;
  476. $Help{FAST}        = "                --fast   skip as much as possible\n" ;
  477. $Help{FIGURES}     = "             --figures   typeset figure directory\n" ;
  478. $Help{figures}     =
  479. $Help{FIGURES}     . "                           =a : room for corrections\n"
  480.                    . "                           =b : just graphics\n"
  481.                    . "                           =c : one (cropped) per page\n"
  482.                    . "         --paperoffset   room left at paper border\n" ;
  483. $Help{FINAL}       = "               --final   add a final run without skipping\n" ;
  484. $Help{FORMAT}      = "              --format   fmt file\n" ;
  485. $Help{format}      =
  486. $Help{FORMAT}      . "                           =name : format file (memory dump) \n" ;
  487. $Help{INTERFACE}   = "           --interface   user interface\n" ;
  488. $Help{interface}   =
  489. $Help{INTERFACE}   . "                           =en : English\n"
  490.                    . "                           =nl : Dutch\n"
  491.                    . "                           =de : German\n"
  492.                    . "                           =cz : Czech\n"
  493.                    . "                           =uk : Brittish\n" ;
  494. $Help{LANGUAGE}    = "            --language   main hyphenation language \n" ;
  495. $Help{language}    =
  496. $Help{LANGUAGE}    . "                           =xx : standard abbreviation \n" ;
  497. $Help{LISTING}     = "             --listing   produce a verbatim listing\n" ;
  498. $Help{listing}     =
  499. $Help{LISTING}     . "           --backspace   inner margin of the page\n" .
  500.                      "            --topspace   top/bottom margin of the page\n" ;
  501. $Help{MAKE}        = "                --make   build format files \n" ;
  502. $Help{make}        =
  503. $Help{MAKE}        . "            --language   patterns to include\n" .
  504.                      "            --bodyfont   bodyfont to preload\n" ;
  505. $Help{MODE}        = "                --mode   running mode \n" ;
  506. $Help{mode}        =
  507. $Help{MODE}        . "                           =list : modes to set\n" ;
  508. $Help{MODULE}      = "              --module   typeset tex/pl/mp module\n" ;
  509. $Help{MPTEX}       = "               --mptex   run an MetaPost btex-etex cycle\n" ;
  510. $Help{NOARRANGE}   = "           --noarrange   process but ignore arrange\n" ;
  511. $Help{NOMP}        = "                --nomp   don't run MetaPost\n" ;
  512. $Help{ONCE}        = "                --once   run TeX only once (no TeXUtil either)\n" ;
  513. $Help{OUTPUT}      = "              --output   specials to use\n" ;
  514. $Help{output}      =
  515. $Help{OUTPUT}      . "                           =pdftex\n"
  516.                    . "                           =dvips\n"
  517.                    . "                           =dvipsone\n"
  518.                    . "                           =dviwindo\n"
  519.                    . "                           =dviview\n" ;
  520. $Help{PASSON}      = '              --passon   switches to pass to TeX ("--src" for MikTeX)' . "\n" ;
  521. $Help{PAGES}       = "               --pages   pages to output\n" ;
  522. $Help{pages}       =
  523. $Help{PAGES}       . "                           =odd   : odd pages\n" .
  524.                      "                           =even  : even pages\n" .
  525.                      "                           =x,y:z : pages x and y to z\n" ;
  526. $Help{PAPER}       = "               --paper   paper input and output format\n" ;
  527. $Help{paper}       =
  528. $Help{PAPER}       . "                           =a4a3 : A4 printed on A3\n" .
  529.                      "                           =a5a4 : A5 printed on A4\n" ;
  530. $Help{PDF}         = "                 --pdf   produce PDF directly using pdf(e)tex\n" ;
  531. $Help{PDFARRANGE}  = "          --pdfarrange   arrange pdf pages\n" ;
  532. $Help{pdfarrange}  =
  533. $Help{PDFARRANGE}  . "         --paperoffset   room left at paper border\n" .
  534.                      "               --paper   paper format\n" .
  535.                      "            --noduplex   single sided\n" .
  536.                      "           --backspace   inner margin of the page\n" .
  537.                      "            --topspace   top/bottom margin of the page\n" .
  538.                      "            --markings   add cutmarks\n" .
  539.                      "            --addempty   add empty page after\n" .
  540.                      "           --textwidth   width of the original (one sided) text\n" ;
  541. $Help{PDFCOMBINE}  = "          --pdfcombine   combine pages to one page\n" ; 
  542. $Help{pdfcombine}  =   
  543. $Help{PDFCOMBINE}  . "         --paperformat   paper format\n" .
  544.                      "         --combination   n*m pages per page\n" .
  545.                      "         --paperoffset   room left at paper border\n" ;
  546. $Help{PDFCOPY}     = "             --pdfcopy   scale pages down/up\n" ;
  547. $Help{pdfcopy}     = 
  548. $Help{PDFCOPY}     . "               --scale   new page scale\n" ;  
  549. $Help{PDFSELECT}   = "           --pdfselect   select pdf pages\n" ;
  550. $Help{pdfselect}   =
  551. $Help{PDFSELECT}   = "           --selection   pages to select\n" .
  552.                      "                           =odd   : odd pages\n" .
  553.                      "                           =even  : even pages\n" .
  554.                      "                           =x,y:z : pages x and y to z\n" .
  555.                      "         --paperoffset   room left at paper border\n" .
  556.                      "         --paperformat   paper format\n" .
  557.                      "           --backspace   inner margin of the page\n" .
  558.                      "            --topspace   top/bottom margin of the page\n" .
  559.                      "            --markings   add cutmarks\n" .
  560.                      "            --addempty   add empty page after\n" .
  561.                      "           --textwidth   width of the original (one sided) text\n" ;
  562. $Help{PRINT}       = "               --print   page imposition scheme\n" ;
  563. $Help{print}       =
  564. $Help{PRINT}       . "                             =up : 2 pages per sheet doublesided           \n" .
  565.                      "                           =down : 2 rotated pages per sheet doublesided \n" ;
  566. $Help{RESULT}      = "              --result   resulting file \n" ;
  567. $Help{result}      =
  568. $Help{RESULT}      . "                           =name : filename \n" ;
  569. $Help{RUNS}        = "                --runs   maximum number of TeX runs \n" ;
  570. $Help{runs}        =
  571. $Help{RUNS}        . "                           =n : number of runs\n" ;
  572. $Help{SILENT}      = "              --silent   minimize (status) messages\n" ;
  573. $Help{TEX}         = "                 --tex   TeX binary \n" ;
  574. $Help{tex}         =
  575. $Help{TEX}         . "                           =name : binary of executable \n" ;
  576. $Help{VERBOSE}     = "             --verbose   shows some additional info \n" ;
  577. $Help{HELP}        = "                --help   show this or more, e.g. '--help interface'\n" ;
  578.  
  579. if ($HelpAsked)
  580.   { if (@ARGV)
  581.       { foreach (@ARGV) { s/\-//go ; print "$Help{$_}\n" } }
  582.     else
  583.       { print $Help{ARRANGE}     ;
  584.         print $Help{BATCH}       ;
  585.         print $Help{CENTERPAGE}  ;
  586.         print $Help{COLOR}       ;
  587.         print $Help{CONVERT}     ;
  588.         print $Help{ENVIRONMENT} ;
  589.         print $Help{FAST}        ;
  590.         print $Help{FIGURES}     ;
  591.         print $Help{FINAL}       ;
  592.         print $Help{FORMAT}      ;
  593.         print $Help{INTERFACE}   ;
  594.         print $Help{LISTING}     ;
  595.         print $Help{LANGUAGE}    ;
  596.         print $Help{MAKE}        ;
  597.         print $Help{MODE}        ;
  598.         print $Help{MODULE}      ;
  599.         print $Help{MPTEX}       ;
  600.         print $Help{NOARRANGE}   ;
  601.         print $Help{NOMP}        ;
  602.         print $Help{ONCE}        ;
  603.         print $Help{OUTPUT}      ;
  604.         print $Help{PAGES}       ;
  605.         print $Help{PAPER}       ;
  606.         print $Help{PASSON}      ;
  607.         print $Help{PDFARRANGE}  ;
  608.         print $Help{PDFCOMBINE}  ;
  609.         print $Help{PDFCOPY}     ;
  610.         print $Help{PDFSELECT}   ;
  611.         print $Help{PDF}         ;
  612.         print $Help{PRINT}       ;
  613.         print $Help{RESULT}      ;
  614.         print $Help{RUNS}        ;
  615.         print $Help{SILENT}      ;
  616.         print $Help{TEX}         ;
  617.         print $Help{VERBOSE}     ;
  618.         print "\n"               ;
  619.         print $Help{HELP}        ;
  620.         print "\n"               }
  621.     exit 0 }
  622.  
  623. my $FinalRunNeeded = 0 ;
  624.  
  625. sub RunPerlScript
  626.   { my ($ScriptName, $Options) = @_ ;
  627.     if ($dosish)
  628.       { system ("perl $TeXScriptsPath$ScriptName.pl $Options") }
  629.     else
  630.       { system ("$ScriptName $Options") } }
  631.  
  632. sub ConvertXMLFile
  633.   { my $FileName = shift ; RunPerlScript($SGMLtoTeX, "$FileName.xml") }
  634.  
  635. sub ConvertSGMLFile
  636.   { my $FileName = shift ; RunPerlScript($SGMLtoTeX, "$FileName.sgm") }
  637.  
  638. my $FullFormat = '' ;
  639.  
  640. sub CheckOutputFormat
  641.   { my $Ok = 1 ;
  642.     if ($OutputFormat ne 'standard')
  643.       { my @OutputFormat = split(/,/,$OutputFormat) ;
  644.         foreach my $F (@OutputFormat)
  645.           { if (defined($OutputFormats{lc $F}))
  646.               { my $OF = $OutputFormats{lc $F} ;
  647.                 next if (",$FullFormat," =~ /\,$OF\,/) ;
  648.                 if ($FullFormat) { $FullFormat .= "," }
  649.                 $FullFormat .= "$OutputFormats{lc $F}" }
  650.             else
  651.               { $Ok = 0 } }
  652.         if (!$Ok)
  653.           { print $Help{output} }
  654.         elsif ($FullFormat)
  655.           { print OPT "\\setupoutput[$FullFormat]\n" } }
  656.     unless ($FullFormat)
  657.       { $FullFormat = $OutputFormat } } # 'standard' to terminal
  658.  
  659. sub MakeOptionFile
  660.   { my ($FinalRun, $FastDisabled, $JobName) = @_ ;
  661.     open (OPT, ">$JobName.top") ;
  662.     print OPT "\\unprotect\n" ;
  663.     $MainLanguage = lc $MainLanguage ;
  664.     unless ($MainLanguage eq "standard")
  665.       { print OPT "\\setuplanguage[$MainLanguage]\n" }
  666. #    my $Ok = 1 ;
  667. #    if ($OutputFormat ne 'standard')
  668. #      { my @OutputFormat = split(/,/,$OutputFormat) ;
  669. #        foreach my $F (@OutputFormat)
  670. #          { if (defined($OutputFormats{lc $F}))
  671. #              { my $OF = $OutputFormats{lc $F} ;
  672. #                next if (",$FullFormat," =~ /\,$OF\,/) ;
  673. #                if ($FullFormat) { $FullFormat .= "," }
  674. #                $FullFormat .= "$OutputFormats{lc $F}" }
  675. #            else
  676. #              { $Ok = 0 } }
  677. #        if (!$Ok)
  678. #          { print $Help{output} }
  679. #        elsif ($FullFormat)
  680. #          { print OPT "\\setupoutput[$FullFormat]\n" } }
  681. #    unless ($FullFormat)
  682. #      { $FullFormat = $OutputFormat } # 'standard' to terminal
  683. #
  684.     if ($FullFormat ne 'standard')
  685.       { print OPT "\\setupoutput[$FullFormat]\n" }
  686. #
  687.     if ($EnterBatchMode)
  688.       { print OPT "\\batchmode\n" }
  689.     if ($UseColor)
  690.       { print OPT "\\setupcolors[\\c!status=\\v!start]\n" }
  691.     if ($NoMPMode)
  692.       { print OPT "\\runMPgraphicsfalse\n" }
  693.     if (($FastMode)&&(!$FastDisabled))
  694.       { print OPT "\\fastmode\n" }
  695.     if ($SilentMode)
  696.       { print OPT "\\silentmode\n" }
  697.     if ($SetupPath)
  698.       { print OPT "\\setupsystem[\\c!gebied=\{$SetupPath\}]\n" }
  699.     $_ = $PaperFormat ;
  700.    #unless (($PdfArrange)||($PdfSelect)||($PdfCombine)||($PdfCopy))
  701.     unless (($PdfSelect)||($PdfCombine)||($PdfCopy))
  702.       { if (/.4.3/goi)
  703.           { print OPT "\\stelpapierformaatin[A4][A3]\n" }
  704.         elsif (/.5.4/goi)
  705.           { print OPT "\\stelpapierformaatin[A5][A4]\n" }
  706.         elsif (!/standard/)
  707.           { print $Help{paper} } }
  708.     if ($CenterPage)
  709.       { print OPT "\\stellayoutin[\\c!plaats=\\v!midden,\\c!markering=\\v!aan]\n" }
  710.     if ($NoArrange)
  711.       { print OPT "\\stelarrangerenin[\\v!blokkeer]\n" }
  712.     elsif ($Arrange)
  713.       { $FinalRunNeeded = 1 ;
  714.         unless ($FinalRun)
  715.           { print OPT "\\stelarrangerenin[\\v!blokkeer]\n" } }
  716.     else
  717.       { $_ = $PrintFormat ;
  718.         if (/.*up/goi)
  719.           { $FinalRunNeeded = 1 ;
  720.             if ($FinalRun)
  721.               { print OPT "\\stelarrangerenin[2UP,\\v!geroteerd,\\v!dubbelzijdig]\n" } }
  722.         elsif (/.*down/goi)
  723.           { $FinalRunNeeded = 1 ;
  724.             if ($FinalRun)
  725.               { print OPT "\\stelarrangerenin[2DOWN,\\v!geroteerd,\\v!dubbelzijdig]\n" } }
  726.         elsif (!/standard/goi) { print $Help{"print"} } }
  727.     if ($Mode)
  728.       { print OPT "\\enablemode[$Mode]\n" }
  729.     if ($Pages)
  730.       { if (lc $Pages eq "odd")
  731.           { print OPT "\\chardef\\whichpagetoshipout=1\n" }
  732.         elsif (lc $Pages eq "even")
  733.           { print OPT "\\chardef\\whichpagetoshipout=2\n" }
  734.         else
  735.           { my @Pages = split (/\,/,$Pages) ;
  736.             $Pages = '' ;
  737.             foreach my $page (@Pages)
  738.               { if ($page =~ /\:/)
  739.                   { my ($from,$to) = split (/\:/,$page) ;
  740.                     foreach (my $i=$from;$i<=$to;$i++)
  741.                      { $Pages .= $i . ',' } }
  742.                 else
  743.                   { $Pages .= $page . ',' } }
  744.             chop $Pages ;
  745.             print OPT "\\def\\pagestoshipout\{$Pages\}\n" } }
  746.     print OPT "\\protect\n" ;
  747.     if ($Environment)
  748.       { foreach my $E (split(/,/,$Environment)) { print OPT "\\omgeving $E\n" } }
  749.     close (OPT) ;
  750.     if (open(TMP,">cont-opt.bak")&&open(TMP,"<cont-opt.tex"))
  751.       { while (<OPT>) { print TMP $_ } } }
  752.  
  753. my $UserFileOk = 0 ;
  754. my @MainLanguages ;
  755. my $AllLanguages = '' ; 
  756.  
  757. sub MakeUserFile
  758.   { $UserFileOk = 0 ;
  759.     return if (($MainLanguage eq 'standard')&&
  760.                ($MainBodyFont eq 'standard')) ;
  761.     print "   preparing user file : cont-fmt.tex\n" ;
  762.     open (USR, ">cont-fmt.tex") ;
  763.     print USR "\\unprotect\n" ;
  764.     $AllLanguages = $MainLanguage ;  
  765.     if ($MainLanguage ne 'standard')
  766.       { @MainLanguages = split (/\,/,$MainLanguage) ;
  767.         foreach (@MainLanguages)
  768.           { print USR "\\installlanguage[\\s!$_][\\c!status=\\v!start]\n" }
  769.         $MainLanguage = $MainLanguages[0] ;
  770.         print USR "\\setupcurrentlanguage[\\s!$MainLanguage]\n" }
  771.     if ($MainBodyFont ne 'standard')
  772.       { print USR "\\definefilesynonym[font-cmr][font-$MainBodyFont]\n" }
  773.     print USR "\\protect\n" ;
  774.     print USR "\\endinput\n" ;
  775.     close (USR) ;
  776.     ReportUserFile () ;
  777.     print "\n" ;
  778.     $UserFileOk = 1 }
  779.  
  780. sub RestoreUserFile
  781.   { unlink "cont-fmt.log" ;
  782.     rename "cont-fmt.tex", "cont-fmt.log" ;
  783.     ReportUserFile () }  
  784.  
  785. sub ReportUserFile
  786.   { return unless ($UserFileOk) ; 
  787.     print "\n" ; 
  788.     if ($MainLanguage ne 'standard')
  789.       { print "   additional patterns : $AllLanguages\n" ;
  790.         print "      default language : $MainLanguage\n" }
  791.     if ($MainBodyFont ne 'standard')
  792.       { print "      default bodyfont : $MainBodyFont\n" } }
  793.  
  794. sub CompareFiles
  795.  { my ($File1, $File2) = @_ ;
  796.    my $Str1 = my $Str2 = '' ;
  797.    if ((-s $File1 eq -s $File2)&&(open(TUO1,$File1))&&(open(TUO2,$File2)))
  798.      { while(1)
  799.         { $Str1 = <TUO1> ;
  800.           $Str2 = <TUO2> ;
  801.           if ($Str1 eq $Str2)
  802.             { unless ($Str1) { close(TUO1) ; close(TUO2) ; return 1 } }
  803.           else
  804.             { close(TUO1) ; close(TUO2) ; return 0 } } }
  805.    else
  806.      { return 0 } }
  807.  
  808. my $ConTeXtVersion = "unknown" ;
  809. my $ConTeXtModes   = '' ;
  810.  
  811. sub ScanPreamble
  812.   { my ($FileName) = @_ ;
  813.     open (TEX, $FileName) ;
  814.     while (<TEX>)
  815.      { chomp ;
  816.        if (/^\%.*/)
  817.          { if (/tex=([a-z]*)/goi)                  { $TeXExecutable    = $1 }
  818.            if (/translat.*?=([\:\/0-9\-a-z]*)/goi) { $TeXTranslation   = $1 }
  819.            if (/program=([a-z]*)/goi)              { $TeXExecutable    = $1 }
  820.            if (/modes=([a-z\,]*)/goi)              { $ConTeXtModes     = $1 }
  821.            if (/output=([a-z\,]*)/goi)             { $OutputFormat     = $1 }
  822.            if ($ConTeXtInterface eq "unknown")
  823.              { if (/format=([a-z]*)/goi)           { $ConTeXtInterface = $ConTeXtInterfaces{$1}  }
  824.                if (/interface=([a-z]*)/goi)        { $ConTeXtInterface = $ConTeXtInterfaces{$1} } }
  825.            if (/version=([a-z]*)/goi)              { $ConTeXtVersion   = $1 } }
  826.        else
  827.          { last } }
  828.     close(TEX) }
  829.  
  830. sub ScanContent
  831.   { my ($ConTeXtInput) = @_ ;
  832.     open (TEX, $ConTeXtInput) ;
  833.     while (<TEX>)
  834.       { if    (/\\(starttekst|stoptekst|startonderdeel)/)
  835.           { $ConTeXtInterface = "nl" ; last }
  836.         elsif (/\\(stelle|verwende|umgebung|benutze)/)
  837.           { $ConTeXtInterface = "de" ; last }
  838.         elsif (/\\(stel|gebruik|omgeving)/)
  839.           { $ConTeXtInterface = "nl" ; last }
  840.         elsif (/\\(use|setup|environment)/)
  841.           { $ConTeXtInterface = "en" ; last }
  842.         elsif (/(hoogte|breedte|letter)=/)
  843.           { $ConTeXtInterface = "nl" ; last }
  844.         elsif (/(height|width|style)=/)
  845.           { $ConTeXtInterface = "en" ; last }
  846.         elsif (/(hoehe|breite|schrift)=/)
  847.           { $ConTeXtInterface = "de" ; last }
  848.         elsif (/externfiguur/)
  849.           { $ConTeXtInterface = "nl" ; last }
  850.         elsif (/externalfigure/)
  851.           { $ConTeXtInterface = "en" ; last }
  852.         elsif (/externeabbildung/)
  853.           { $ConTeXtInterface = "de" ; last } }
  854.     close (TEX) }
  855.  
  856. if ($ConTeXtInterfaces{$ConTeXtInterface})
  857.   { $ConTeXtInterface = $ConTeXtInterfaces{$ConTeXtInterface} }
  858.  
  859. my $Problems = 0 ;
  860.  
  861. sub RunTeX
  862.   { my $JobName = shift ;
  863.     my $StartTime = time ;
  864.     my $cmd ;
  865.     my $TeXProgNameFlag ;
  866.     if (!$dosish)
  867.       { $TeXProgramPath = '' ;
  868.         $TeXFormatPath = '' ;
  869.         if (!$TeXProgNameFlag&&($Format=~/^cont/))
  870.           { $TeXProgNameFlag = "-progname=context" } }
  871.     $cmd  = "$TeXProgramPath$TeXExecutable $TeXProgNameFlag " .
  872.             "$TeXPassString $PassOn " ;
  873.     if ($TeXTranslation ne '')
  874.       { $cmd .= "-translate-file=$TeXTranslation " }
  875.     $cmd .= "$TeXFormatFlag$TeXFormatPath$Format $JobName" ;
  876.     if ($Verbose) { print "\n$cmd\n\n" }
  877.     $Problems = system ( "$cmd" ) ;
  878.     my $StopTime = time - $StartTime ;
  879.     print "\n              run time : $StopTime seconds\n" ;
  880.     return $Problems }
  881.  
  882. sub PushResult
  883.   { if ($Result)
  884.       { print "            outputfile : $Result\n" ;
  885.         unlink ("texexec.tuo") ; rename ("$_[0].tuo", "texexec.tuo") ;
  886.         unlink ("texexec.log") ; rename ("$_[0].log", "texexec.log") ;
  887.         unlink ("texexec.dvi") ; rename ("$_[0].dvi", "texexec.dvi") ;
  888.         unlink ("texexec.pdf") ; rename ("$_[0].pdf", "texexec.pdf") ;
  889.         if (-f "$Result.tuo")
  890.           { unlink ("$_[0].tuo") ;
  891.             rename ("$Result.tuo", "$_[0].tuo") } } }
  892.  
  893. sub PopResult
  894.   { if ($Result)
  895.       { print "              renaming : $_[0] to $Result\n" ;
  896.         unlink ("$Result.tuo") ; rename ("$_[0].tuo", "$Result.tuo") ;
  897.         unlink ("$Result.log") ; rename ("$_[0].log", "$Result.log") ;
  898.         unlink ("$Result.dvi") ; rename ("$_[0].dvi", "$Result.dvi") ;
  899.         unlink ("$Result.pdf") ; rename ("$_[0].pdf", "$Result.pdf") ;
  900.         rename ("texexec.tuo", "$_[0].tuo") ;
  901.         rename ("texexec.log", "$_[0].log") ;
  902.         rename ("texexec.dvi", "$_[0].dvi") ;
  903.         rename ("texexec.pdf", "$_[0].pdf") } }
  904.  
  905. sub RunConTeXtFile
  906.   { my ($JobName) = @_ ;
  907.     $JobName =~ s/\\/\//goi ;
  908.     if (-e "$JobName.tex")
  909.       { ScanPreamble ("$JobName.tex") ;
  910.         if ($ConTeXtInterface eq "unknown")
  911.           { ScanContent ("$JobName.tex") }
  912.         if ($ConTeXtInterface eq "unknown")
  913.           { $ConTeXtInterface = $UserInterface }
  914.         if (lc $Convert eq "xml")
  915.           { print "             xml input : $JobName.xml\n" ;
  916.             ConvertXMLFile ($JobName) }
  917.         elsif (lc $Convert eq "sgml")
  918.           { print "            sgml input : $JobName.sgm\n" ;
  919.             ConvertSGMLFile ($JobName) }
  920.         CheckOutputFormat ;
  921.         my $StopRunning = 0 ;
  922.         if ($Format eq '')
  923.           { $Format = "cont-$ConTeXtInterface" }
  924.         print "            executable : $TeXProgramPath$TeXExecutable\n" ;
  925.         print "                format : $TeXFormatPath$Format\n" ;
  926.         print "             inputfile : $JobName\n" ;
  927.         print "                output : $FullFormat\n" ;
  928.         print "             interface : $ConTeXtInterface\n" ;
  929.         if ($TeXTranslation ne '')
  930.           { print "           translation : $TeXTranslation\n" }
  931.         my $Options = '' ;
  932.         if ($FastMode)       { $Options .= " fast" }
  933.         if ($FinalMode)      { $Options .= " final" }
  934.         if ($Verbose)        { $Options .= " verbose" }
  935.         if ($TypesetListing) { $Options .= " listing" }
  936.         if ($TypesetModule)  { $Options .= " module" }
  937.         if ($TypesetFigures) { $Options .= " figures" }
  938.         if ($MakeFormats)    { $Options .= " make" }
  939.         if ($RunOnce)        { $Options .= " once" }
  940.         if ($UseColor)       { $Options .= " color" }
  941.         if ($EnterBatchMode) { $Options .= " batch" }
  942.         if ($NoMPMode)       { $Options .= " nomp" }
  943.         if ($CenterPage)     { $Options .= " center" }
  944.         if ($Arrange)        { $Options .= " arrange" }
  945.         if ($NoArrange)      { $Options .= " no-arrange" }
  946.         if ($Options)
  947.           { print "               options :$Options\n" }
  948.         if ($ConTeXtModes)
  949.           { print "        possible modes : $ConTeXtModes\n" }
  950.         if ($Mode)
  951.           { print "          current mode : $Mode\n" }
  952.         else
  953.           { print "          current mode : all\n" }
  954.         if ($Environment)
  955.           { print "          environments : $Environment\n" }
  956.         PushResult($JobName) ;
  957.         $Problems = 0 ;
  958.         my $TeXRuns = 0 ;
  959.         if (($PdfArrange)||($PdfSelect)||($RunOnce))
  960.           { MakeOptionFile (1, 1, $JobName) ;
  961.             print "\n" ;
  962.             $Problems = RunTeX($JobName) ;
  963.             PopResult($JobName) }
  964.         else
  965.           { while (!$StopRunning&&($TeXRuns<$NOfRuns)&&(!$Problems))
  966.              { MakeOptionFile (0, 0, $JobName) ;
  967.                ++$TeXRuns ;
  968.                print "               TeX run : $TeXRuns\n\n" ;
  969.                $Problems = RunTeX($JobName) ;
  970.                if ((!$Problems)&&($NOfRuns>1))
  971.                  { if (!$NoMPMode)
  972.                      { my $MPJobName = '' ;
  973.                        if (-e "$JobName-mpgraph.mp")
  974.                          { $MPJobName = "$JobName-mpgraph.mp" }
  975.                        elsif (-e "mpgraph.mp")
  976.                          { $MPJobName = "mpgraph.mp" }
  977.                        if ($MPJobName ne "")  
  978.                          { if (open(MP, "$MPJobName"))
  979.                             { $_ = <MP> ;
  980.                               my $RuntimeGraphic = /runtime generated graphic/i ;
  981.                               close(MP) ;
  982.                               if (!$RuntimeGraphic)
  983.                                 { if ($MpExecutable ne '')
  984.                                     { print "   generating graphics : metaposting MPJobName\n" ;
  985.                                       $Problems = system ("$MpExecutable $MPJobName") }
  986.                                   else
  987.                                     { print "   generating graphics : metapost cannot be run\n" } } } } }
  988.                    unless ($Problems)
  989.                      { unlink "$JobName.tup" ;
  990.                        rename "$JobName.tuo", "$JobName.tup" ;
  991.                        print "  sorting and checking : running texutil\n" ;
  992. my $TcXSwitch = '' ; 
  993. if ($TcXPath ne '') { $TcXSwitch = "--tcxpath=$TcXPath" }  
  994.                        RunPerlScript
  995.                          ($TeXUtil, "--ref --ij --high $TcXPath $JobName" );
  996.                        if (-e "$JobName.tuo")
  997.                          { $StopRunning =
  998.                            CompareFiles("$JobName.tup", "$JobName.tuo") }
  999.                        else
  1000.                          { $StopRunning = 1 } # otherwise potential loop
  1001.                        if (!$StopRunning)
  1002.                          { print "\n utility file analysis : another run needed\n" } } } }
  1003.            if ((!$Problems)&&(($FinalMode||$FinalRunNeeded))&&($NOfRuns>1))
  1004.              { MakeOptionFile (1, $FinalMode, $JobName) ;
  1005.                print "         final TeX run : $TeXRuns\n\n" ;
  1006.                $Problems = RunTeX($JobName) }
  1007.            unlink "$JobName.tup" ; # previous tuo file
  1008.            unlink "$JobName.top" ; # runtime option file
  1009.            PopResult($JobName) } } }
  1010.  
  1011. sub RunSomeTeXFile
  1012.   { my ($JobName) = @_ ;
  1013.     if (-e "$JobName.tex")
  1014.       { PushResult($JobName) ;
  1015.         print "            executable : $TeXProgramPath$TeXExecutable\n" ;
  1016.         print "                format : $TeXFormatPath$Format\n" ;
  1017.         print "             inputfile : $JobName\n" ;
  1018.         $Problems = RunTeX($JobName) ;
  1019.         PopResult($JobName) } }
  1020.  
  1021. my $ModuleFile  = "texexec" ;
  1022. my $ListingFile = "texexec" ;
  1023. my $FiguresFile = "texexec" ;
  1024. my $ArrangeFile = "texexec" ;
  1025. my $SelectFile  = "texexec" ;
  1026. my $CopyFile    = "texexec" ;
  1027. my $CombineFile = "texexec" ;
  1028.  
  1029. sub RunModule
  1030.   { my ($FileName) = @_ ;
  1031.     if ((-e "$FileName.tex")||(-e "$FileName.pl")||(-e "$FileName.mp")||
  1032.                               (-e "$FileName.pm"))
  1033.       { RunPerlScript ($TeXUtil,
  1034.           "--documents $FileName.pl $FileName.pm $FileName.mp $FileName.tex" ) ;
  1035.         print "                module : $FileName\n\n" ;
  1036.         open (MOD, ">$ModuleFile.tex") ;
  1037.         print MOD "% format=dutch        \n" ;
  1038.         print MOD "\\starttekst          \n" ;
  1039.         print MOD "\\input modu-abr      \n" ;
  1040.         print MOD "\\input modu-arg      \n" ;
  1041.         print MOD "\\input modu-env      \n" ;
  1042.         print MOD "\\input modu-mod      \n" ;
  1043.         print MOD "\\input modu-pap      \n" ;
  1044.         print MOD "\\def\\ModuleNumber{1}\n" ;
  1045.         print MOD "\\input $FileName.ted \n" ;
  1046.         print MOD "\\stoptekst           \n" ;
  1047.         close (MOD) ;
  1048.         $ConTeXtInterface = "nl" ;
  1049.         RunConTeXtFile($ModuleFile) ;
  1050.         if ($FileName ne $ModuleFile)
  1051.           { foreach my $FileSuffix ("dvi", "pdf", "tui", "tuo", "log")
  1052.              { unlink ("$FileName.$FileSuffix") ;
  1053.                rename ("$ModuleFile.$FileSuffix", "$FileName.$FileSuffix") } }
  1054.         unlink ("$ModuleFile.tex") } }
  1055.  
  1056. sub RunFigures
  1057.   { my @Files = @_ ;
  1058.     $TypesetFigures = lc $TypesetFigures ;
  1059.     return unless ($TypesetFigures =~ /[abc]/o) ;
  1060.     unlink "$FiguresFile.pdf" ;
  1061.     if (@Files) { RunPerlScript ($TeXUtil, "--figures @Files" ) }
  1062.     open (FIG, ">$FiguresFile.tex") ;
  1063.     print FIG "% format=english\n" ;
  1064.     print FIG "\\starttext\n" ;
  1065.     print FIG "\\setuplayout\n" ;
  1066.     print FIG "  [topspace=1.5cm,backspace=1.5cm,\n" ;
  1067.     print FIG "   header=1.5cm,footer=0pt,\n" ;
  1068.     print FIG "   width=middle,height=middle]\n" ;
  1069.     print FIG "\\showexternalfigures[alternative=$TypesetFigures,offset=$PaperOffset]\n" ;
  1070.     print FIG "\\stoptext\n" ;
  1071.     close(FIG) ;
  1072.     $ConTeXtInterface = "en" ;
  1073.     RunConTeXtFile($FiguresFile) }
  1074.  
  1075. sub RunListing
  1076.   { my $FileName = shift ;
  1077.     return unless -f $FileName ;
  1078.     print "            input file : $FileName\n" ;
  1079.     if ($BackSpace eq "0pt")
  1080.       { $BackSpace="1.5cm" }
  1081.     else
  1082.       { print "             backspace : $BackSpace\n" }
  1083.     if ($TopSpace eq "0pt")
  1084.       { $TopSpace="1.5cm" }
  1085.     else
  1086.       { print "              topspace : $TopSpace\n" }
  1087.     open (LIS, ">$ListingFile.tex") ;
  1088.     print LIS "% format=english\n" ;
  1089.     print LIS "\\starttext\n" ;
  1090.     print LIS "\\setupbodyfont[11pt,tt]\n" ;
  1091.     print LIS "\\setuplayout\n" ;
  1092.     print LIS "  [topspace=$TopSpace,backspace=$BackSpace,\n" ;
  1093.     print LIS "   header=0cm,footer=1.5cm,\n" ;
  1094.     print LIS "   width=middle,height=middle]\n" ;
  1095.     print LIS "\\setupfootertexts[$FileName][pagenumber]\n" ;
  1096.     print LIS "\\typefile\{$FileName\}\n" ;
  1097.     print LIS "\\stoptext\n" ;
  1098.     close(LIS) ;
  1099.     $ConTeXtInterface = "en" ;
  1100.     RunConTeXtFile($ListingFile) }
  1101.  
  1102. sub DetermineNOfPdfPages
  1103.   { my $FileName = shift ;
  1104.     my $NOfPages = 0 ;
  1105.     if (($FileName =~ /\.pdf$/io)&&(open(PDF,$FileName)))
  1106.       { binmode PDF ;
  1107.         my $PagesFound = 0 ;
  1108.         while (<PDF>)
  1109.           { if (/\/Type \/Pages/o)
  1110.               { $PagesFound = 1 }
  1111.             if ($PagesFound)
  1112.               { if (/\/Count\s*(\d*)/o)
  1113.                   { if ($1>$NOfPages) { $NOfPages = $1 } }
  1114.                 elsif (/endobj/o)
  1115.                   { $PagesFound = 0 } } }
  1116.         close ( PDF ) }
  1117.     return $NOfPages }
  1118.  
  1119. sub RunArrange
  1120.   { my @files = @_ ;
  1121.     print "             backspace : $BackSpace\n" ;
  1122.     print "              topspace : $TopSpace\n" ;
  1123.     print "           paperoffset : $PaperOffset\n" ;
  1124.     if ($AddEmpty eq '')
  1125.       { print "     empty pages added : none\n" }
  1126.     else
  1127.       { print "     empty pages added : $AddEmpty\n" }
  1128.     if ($TextWidth eq '0pt')
  1129.       { print "             textwidth : unknown\n" }
  1130.     else
  1131.       { print "             textwidth : $TextWidth\n" }
  1132.     open (ARR, ">$ArrangeFile.tex") ;
  1133.     print ARR "% format=english\n" ;
  1134. #    if ($PaperFormat ne 'standard')
  1135. #      { print "           paperformat : $PaperFormat\n" ;
  1136. #        print ARR "\\setuppapersize[$PaperFormat][$PaperFormat]\n" }
  1137.     print ARR "\\definepapersize\n" ;
  1138.     print ARR "  [offset=$PaperOffset]\n";
  1139.     print ARR "\\setuplayout\n" ;
  1140.     print ARR "  [backspace=$BackSpace,\n" ;
  1141.     print ARR "    topspace=$TopSpace,\n" ;
  1142.     if ($Markings)
  1143.       { print ARR "     marking=on,\n" ;
  1144.         print "           cutmarkings : on\n" }
  1145.     print ARR "       width=middle,\n" ;
  1146.     print ARR "      height=middle,\n" ;
  1147.     print ARR "    location=middle,\n" ;
  1148.     print ARR "      header=0pt,\n" ;
  1149.     print ARR "      footer=0pt]\n" ;
  1150.     if ($NoDuplex)
  1151.       { print "                duplex : off\n" }
  1152.     else
  1153.       { print "                duplex : on\n" ;
  1154.         print ARR "\\setuppagenumbering\n" ;
  1155.         print ARR "  [alternative=doublesided]\n" }
  1156.     foreach my $FileName (@files)
  1157.       { my $NOfPages = DetermineNOfPdfPages($FileName) ;
  1158.         if ($NOfPages)
  1159.           { print "               pdffile : $FileName\n" ;
  1160.             print "       number of pages : $NOfPages\n\n" ;
  1161.             print ARR "\\insertpages\n" ;
  1162.             if ($AddEmpty eq '')
  1163.               { print ARR "  [$FileName][n=$NOfPages,width=$TextWidth]\n" }
  1164.             else
  1165.               { print ARR "  [$FileName][$AddEmpty][n=$NOfPages,width=$TextWidth]\n" } } }
  1166.     print ARR "\\stoptext\n" ;
  1167.     close (ARR) ;
  1168.     $ConTeXtInterface = "en" ;
  1169.     RunConTeXtFile($ModuleFile) }
  1170.  
  1171. sub RunSelect
  1172.   { my $FileName = shift ;
  1173.     print "             backspace : $BackSpace\n" ;
  1174.     print "              topspace : $TopSpace\n" ;
  1175.     print "           paperoffset : $PaperOffset\n" ;
  1176.     if ($TextWidth eq '0pt')
  1177.       { print "             textwidth : unknown\n" }
  1178.     else
  1179.       { print "             textwidth : $TextWidth\n" }
  1180.     open (SEL, ">$SelectFile.tex") ;
  1181.     print SEL "% format=english\n" ;
  1182.     if ($PaperFormat ne 'standard')
  1183.       { print "             papersize : $PaperFormat\n" ;
  1184.         print SEL "\\setuppapersize[$PaperFormat][$PaperFormat]\n" }
  1185.     print SEL "\\definepapersize\n" ;
  1186.     print SEL "  [offset=$PaperOffset]\n";
  1187.     print SEL "\\setuplayout\n" ;
  1188.     print SEL "  [backspace=$BackSpace,\n" ;
  1189.     print SEL "    topspace=$TopSpace,\n" ;
  1190.     if ($Markings)
  1191.       { print SEL "     marking=on,\n" ;
  1192.         print "           cutmarkings : on\n" }
  1193.     print SEL "       width=middle,\n" ;
  1194.     print SEL "      height=middle,\n" ;
  1195.     print SEL "    location=middle,\n" ;
  1196.     print SEL "      header=0pt,\n" ;
  1197.     print SEL "      footer=0pt]\n" ;
  1198.    #print SEL "\\setuppagenumbering\n" ;
  1199.    #print SEL "  [alternative=doublesided]\n" ;
  1200.     my $NOfPages = DetermineNOfPdfPages($FileName) ;
  1201.     if (($NOfPages)&&($Selection ne ''))
  1202.       { print "               pdffile : $FileName\n" ;
  1203.         print "       number of pages : $NOfPages\n\n" ;
  1204.         print SEL "\\filterpages\n" ;
  1205.         print SEL "  [$FileName][$Selection][n=$NOfPages,width=$TextWidth]\n" }
  1206.     print SEL "\\stoptext\n" ;
  1207.     close (SEL) ;
  1208.     $ConTeXtInterface = "en" ;
  1209.     RunConTeXtFile($SelectFile) }
  1210.  
  1211. sub RunCopy
  1212.   { my $FileName = shift ;
  1213.     print "                 scale : $PageScale\n" ;
  1214.     if ($PageScale<10) { $PageScale *= 1000 ; sprintf(".0f",$PageScale) } 
  1215.     open (COP, ">$CopyFile.tex") ;
  1216.     print COP "% format=english\n" ;
  1217.     print COP "\\getfiguredimensions\n" ; 
  1218.     print COP "  [$FileName][page=1]\n" ; 
  1219.     print COP "\\definepapersize\n" ; 
  1220.     print COP "  [copy]\n" ; 
  1221.     print COP "  [width=\\naturalfigurewidth,\n" ; 
  1222.     print COP "   height=\\naturalfigureheight]\n" ; 
  1223.     print COP "\\setuppapersize\n" ; 
  1224.     print COP "  [copy][copy]\n" ; 
  1225.     print COP "\\setuplayout\n" ; 
  1226.     print COP "  [location=middle,\n" ; 
  1227.     print COP "   topspace=0pt,\n" ; 
  1228.     print COP "   backspace=0pt,\n" ; 
  1229.     print COP "   header=0pt,\n" ; 
  1230.     print COP "   footer=0pt,\n" ; 
  1231.     print COP "   width=middle,\n" ; 
  1232.     print COP "   height=middle]\n" ; 
  1233.     print COP "\\starttext\n" ; 
  1234.     my $NOfPages = DetermineNOfPdfPages($FileName) ;
  1235.     if ($NOfPages)
  1236.       { print "               pdffile : $FileName\n" ;
  1237.         print "       number of pages : $NOfPages\n\n" ;
  1238.         print COP "\\copypages[$FileName][n=$NOfPages,scale=$PageScale]\n" }
  1239.     print COP "\\stoptext\n" ;
  1240.     close (COP) ;
  1241.     $ConTeXtInterface = "en" ;
  1242.     RunConTeXtFile($CopyFile) }
  1243.  
  1244. sub RunCombine
  1245.   { my $FileName = shift ;
  1246.     my ($nx,$ny) = split (/\*/,$Combination,2) ; 
  1247.     return unless ($nx&&$ny) ;
  1248.     print "           combination : $Combination\n" ;
  1249.     open (COM, ">$CombineFile.tex") ;
  1250.     print COM "% format=english\n" ;
  1251.     if ($PaperFormat ne 'standard') 
  1252.       { print "         papersize : $PaperFormat\n" ;
  1253.         print COM "\\setuppapersize\n" ; 
  1254.         print COM "  [$PaperFormat][$PaperFormat]\n" } 
  1255.     if ($PaperOffset eq '0pt') 
  1256.       { $PaperOffset = '1cm' } 
  1257.     print "          paper offset : $PaperOffset\n" ;
  1258.     print COM "\\setuplayout\n" ; 
  1259.     print COM "  [topspace=$PaperOffset,\n" ; 
  1260.     print COM "   backspace=$PaperOffset,\n" ; 
  1261.     print COM "   header=0pt,\n" ; 
  1262.     print COM "   footer=1cm,\n" ; 
  1263.     print COM "   width=middle,\n" ; 
  1264.     print COM "   height=middle]\n" ; 
  1265.     print COM "\\setupfootertexts\n" ; 
  1266.     print COM "  [$FileName\\space---\\space\\currentdate\\space---\\space\\pagenumber]\n" ; 
  1267.     print COM "\\starttext\n" ; 
  1268.     my $NOfPages = DetermineNOfPdfPages($FileName) ;
  1269.     if ($NOfPages)
  1270.       { print "               pdffile : $FileName\n" ;
  1271.         print "       number of pages : $NOfPages\n\n" ;
  1272.         print COM "\\combinepages[$FileName][n=$NOfPages,nx=$nx,ny=$ny]\n" }
  1273.     print COM "\\stoptext\n" ;
  1274.     close (COM) ;
  1275.     $ConTeXtInterface = "en" ;
  1276.     RunConTeXtFile($CombineFile) }
  1277.  
  1278. sub RunOneFormat
  1279.   { my ($FormatName) = @_ ;
  1280.     my @TeXFormatPath ;
  1281.     my $TeXPrefix = '' ;
  1282.     if ($fmtutil ne '')
  1283.       { my $cmd = "$fmtutil --byfmt $FormatName" ;
  1284.         if ($Verbose) { print "\n$cmd\n\n" }
  1285.         MakeUserFile ; # this works only when the path is kept 
  1286.         $Problems = system ( "$cmd" ) ;
  1287.         RestoreUserFile }
  1288.     else
  1289.       { $Problems = 1 }
  1290.     if ($Problems)
  1291.       { if ($TeXExecutable =~ /etex|eetex|pdfetex|pdfeetex/io)
  1292.           {$TeXPrefix = "*" }
  1293.         my $CurrentPath = cwd() ;
  1294.         if (($TeXFormatPath eq '')&&($kpsewhich ne ''))  
  1295.           { $TeXFormatPath = `$kpsewhich --show-path=fmt` ;
  1296.             chomp $TeXFormatPath ; 
  1297.             $TeXFormatPath =~ s/\.+\;//o ; # should be a sub 
  1298.             $TeXFormatPath =~ s/\;.*//o ; 
  1299.             $TeXFormatPath =~ s/\!//go ;
  1300.             $TeXFormatPath =~ s/\/\//\//go ;
  1301.             $TeXFormatPath =~ s/\\\\/\//go ;
  1302.             $TeXFormatPath =~ s/[\/\\]$// ; 
  1303.             $TeXFormatPath .= '/' ;
  1304.             if (($TeXFormatPath ne '')&&$Verbose) 
  1305.               { print "    located formatpath : $TeXFormatPath\n" } } 
  1306.         if ($TeXFormatPath ne '') 
  1307.           { chdir "$TeXFormatPath" }
  1308.         MakeUserFile ;
  1309.         my $cmd = "$TeXProgramPath$TeXExecutable $TeXVirginFlag " .
  1310.                   "$TeXPassString ${TeXPrefix}$FormatName" ;
  1311.         if ($Verbose) { print "\n$cmd\n\n" }
  1312.         system ( $cmd ) ;
  1313.         RestoreUserFile ;
  1314.         if (($TeXFormatPath ne '')&&($CurrentPath ne '')) 
  1315.           { chdir $CurrentPath } } }
  1316.  
  1317. sub RunFormats
  1318.   { my $ConTeXtFormatsPrefix;
  1319.     if (@ARGV)
  1320.       { @ConTeXtFormats = @ARGV }
  1321.     elsif ($UsedInterfaces ne '')
  1322.       { @ConTeXtFormats = split /\,/,$UsedInterfaces }
  1323.     if ($Format)
  1324.       { @ConTeXtFormats = $Format; $ConTeXtFormatsPrefix='' ; }
  1325.     else
  1326.       { $ConTeXtFormatsPrefix="cont-" ; }
  1327.     foreach my $Interface (@ConTeXtFormats)
  1328.       { RunOneFormat ("$ConTeXtFormatsPrefix$Interface") }
  1329.     print "\n" ;
  1330.     print "            executable : $TeXProgramPath$TeXExecutable\n" ;
  1331.     print "             format(s) : @ConTeXtFormats\n\n" ; }
  1332.  
  1333. sub RunFiles
  1334.   { if ($PdfArrange)
  1335.       { my @arrangedfiles = () ;
  1336.         foreach my $JobName (@ARGV)
  1337.           { unless ($JobName =~ /.*\.pdf$/oi)
  1338.               { if (-f "$JobName.pdf")
  1339.                   { $JobName .= ".pdf" }
  1340.                 else
  1341.                   { $JobName .= ".PDF" } } 
  1342.             push @arrangedfiles, $JobName }
  1343.         if (@arrangedfiles)
  1344.           { RunArrange (@arrangedfiles) } }
  1345.     elsif (($PdfSelect)||($PdfCopy)||($PdfCombine))
  1346.       { my $JobName = $ARGV[0] ;
  1347.         if ($JobName ne '')
  1348.           { unless ($JobName =~ /.*\.pdf$/oi)
  1349.               { if (-f "$JobName.pdf")
  1350.                   { $JobName .= ".pdf" }
  1351.                 else
  1352.                   { $JobName .= ".PDF" } }
  1353.             if ($PdfSelect)
  1354.               { RunSelect ($JobName) } 
  1355.             elsif ($PdfCopy) 
  1356.               { RunCopy ($JobName) } 
  1357.             else
  1358.               { RunCombine ($JobName) } } }
  1359.     else
  1360.       { foreach my $JobName (@ARGV)
  1361.           { $JobName =~ s/\.tex//goi ;
  1362.             if ($TypesetModule)
  1363.               { unless ($Format) { RunModule ($JobName) } }
  1364.             else
  1365.               { if (($Format eq '')||($Format =~ /^cont.*/io))
  1366.                   { RunConTeXtFile ($JobName) }
  1367.                 else
  1368.                   { RunSomeTeXFile ($JobName) } }
  1369.             unless (-s "$JobName.log") { unlink ("$JobName.log") }
  1370.             unless (-s "$JobName.tui") { unlink ("$JobName.tui") } } } }
  1371.  
  1372. sub RunMP
  1373.   { if (($MpExecutable)&&($MpToTeXExecutable)&&($DviToMpExecutable))
  1374.       { foreach my $RawMpName (@ARGV)
  1375.           { my ($MpName, $Rest) = split (/\./, $RawMpName, 2) ;
  1376.             if (-e "$MpName.mp")
  1377.               { if (open(MP, "$MpName.mp"))
  1378.                   { local $/ = "\0777" ; $_ = <MP> ; close(MP) ;
  1379.                     if (/(btex|etex|verbatimtex)/)
  1380.                       { print "       metapost to tex : $MpName\n" ;
  1381.                         $Problems = system ("$MpToTeXExecutable $MpName.mp > $MpName.tex" ) ;
  1382.                         if (-e "$MpName.tex"&& !$Problems)
  1383.                           { if (($Format eq '')||($Format =~ /^cont.*/io))
  1384.                               { RunConTeXtFile ($MpName) }
  1385.                             else
  1386.                               { RunSomeTeXFile ($MpName) }
  1387.                             if (-e "$MpName.dvi"||!$Problems)
  1388.                               { print "       dvi to metapost : $MpName\n" ;
  1389.                                $Problems = system ("$DviToMpExecutable $MpName") } } } }
  1390.  
  1391.                 print "              metapost : $MpName\n" ;
  1392.                 $Problems = system ("$MpExecutable $MpName" ) } } } }
  1393.  
  1394. if ($TypesetListing)
  1395.   { RunListing (@ARGV) }
  1396. elsif ($TypesetFigures)
  1397.   { RunFigures (@ARGV) }
  1398. elsif ($DoMPTeX)
  1399.   { RunMP }
  1400. elsif ($MakeFormats)
  1401.   { RunFormats }
  1402. elsif (@ARGV)
  1403.   { foreach (@ARGV) { $_ =~ s/\.tex//io } @ARGV = <@ARGV> ; RunFiles }
  1404. else
  1405.   { print $Help{HELP} ;
  1406.     unless ($Verbose) { print $Help{VERBOSE} } }
  1407.  
  1408. if (-f "cont-opt.tex")
  1409.   { unlink ("cont-opt.bak") ;
  1410.     rename ("cont-opt.tex", "cont-opt.bak") }
  1411.  
  1412. if ($Problems) { exit 1 }
  1413.